
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>11.循环.md · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="12.函数基础.html" />
    
    
    <link rel="prev" href="10.运算符.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        <li class="header">笔记</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../阶段一笔记/1.操作系统——特殊的软件.html">
            
                <a href="../阶段一笔记/1.操作系统——特殊的软件.html">
            
                    
                    1.操作系统——特殊的软件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../阶段一笔记/2.命令.html">
            
                <a href="../阶段一笔记/2.命令.html">
            
                    
                    2.命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../阶段一笔记/3.SSH客户端的简单使用.html">
            
                <a href="../阶段一笔记/3.SSH客户端的简单使用.html">
            
                    
                    3.SSH客户端的简单使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../阶段一笔记/4.用户权限相关命令.html">
            
                <a href="../阶段一笔记/4.用户权限相关命令.html">
            
                    
                    4.用户权限相关命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../阶段一笔记/5.系统信息相关命令.html">
            
                <a href="../阶段一笔记/5.系统信息相关命令.html">
            
                    
                    5.系统信息相关命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../阶段一笔记/6.vi命令.html">
            
                <a href="../阶段一笔记/6.vi命令.html">
            
                    
                    6.vi命令
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">软件安装及其使用</li>
        
        
    

    
        
        <li class="header">pycharm</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../阶段二笔记/pycharm安装及配置.html">
            
                <a href="../阶段二笔记/pycharm安装及配置.html">
            
                    
                    pycharm安装及配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../阶段二笔记/pycharm使用.html">
            
                <a href="../阶段二笔记/pycharm使用.html">
            
                    
                    pycharm使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../阶段二笔记/pycharm激活问题.html">
            
                <a href="../阶段二笔记/pycharm激活问题.html">
            
                    
                    pycharm激活问题
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">电子书搭建</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../阶段二笔记/gitbook安装.html">
            
                <a href="../阶段二笔记/gitbook安装.html">
            
                    
                    gitbook安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2" >
            
                <span>
            
                    
                    git
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.2.1" data-path="../阶段二笔记/git简要.html">
            
                <a href="../阶段二笔记/git简要.html">
            
                    
                    git简要
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2.2" data-path="../阶段二笔记/git安装及使用.html">
            
                <a href="../阶段二笔记/git安装及使用.html">
            
                    
                    git安装及使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2.3" data-path="../阶段二笔记/git分支管理.html">
            
                <a href="../阶段二笔记/git分支管理.html">
            
                    
                    git分支管理
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="../阶段二笔记/github使用.html">
            
                <a href="../阶段二笔记/github使用.html">
            
                    
                    github使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="../搭建/gitee远程仓库搭建.html">
            
                <a href="../搭建/gitee远程仓库搭建.html">
            
                    
                    gitee远程仓库搭建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="../搭建/客户端与服务端的搭建.html">
            
                <a href="../搭建/客户端与服务端的搭建.html">
            
                    
                    客户端与服务端的搭建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.6" >
            
                <span>
            
                    
                    问题
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.6.1" data-path="../搭建/gitbook build没有summary.html">
            
                <a href="../搭建/gitbook build没有summary.html">
            
                    
                    gitbook build没有summary
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.6.2" data-path="../问题/typora结合picgo实现上传图片到gitee.html">
            
                <a href="../问题/typora结合picgo实现上传图片到gitee.html">
            
                    
                    typora结合picgo实现上传图片到gitee
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">软件工具</li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../阶段二笔记/anaconda下载与使用.html">
            
                <a href="../阶段二笔记/anaconda下载与使用.html">
            
                    
                    anaconda下载与配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="../阶段二笔记/anaconda的使用.html">
            
                <a href="../阶段二笔记/anaconda的使用.html">
            
                    
                    anaconda的使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="../阶段二笔记/python3.6.4下载与安装.html">
            
                <a href="../阶段二笔记/python3.6.4下载与安装.html">
            
                    
                    python3.6.4下载与安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="../阶段二笔记/typora安装及配置.html">
            
                <a href="../阶段二笔记/typora安装及配置.html">
            
                    
                    typora安装及配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="../阶段二笔记/ubuntu  tool安装.html">
            
                <a href="../阶段二笔记/ubuntu  tool安装.html">
            
                    
                    ubuntu  tool安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="../阶段二笔记/Jetbrains系列产品重置试用方法.html">
            
                <a href="../阶段二笔记/Jetbrains系列产品重置试用方法.html">
            
                    
                    Jetbrains系列产品重置试用方法
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">python学习</li>
        
        
    

    
        
        <li class="header">面对过程</li>
        
        
    
        <li class="chapter " data-level="7.1" data-path="0.python学习.html">
            
                <a href="0.python学习.html">
            
                    
                    0.python学习
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="1.python简介.html">
            
                <a href="1.python简介.html">
            
                    
                    1.python简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.3" data-path="2.python程序no.1.html">
            
                <a href="2.python程序no.1.html">
            
                    
                    2.python程序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.4" data-path="3.多文件项目的演练.html">
            
                <a href="3.多文件项目的演练.html">
            
                    
                    3.多文件项目的演练
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.5" data-path="4.程序注释.html">
            
                <a href="4.程序注释.html">
            
                    
                    4.程序注释
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.6" data-path="5.算数运算符.html">
            
                <a href="5.算数运算符.html">
            
                    
                    5.算数运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.7" data-path="6.程序执行原理（科普）.html">
            
                <a href="6.程序执行原理（科普）.html">
            
                    
                    6.程序执行原理（科普）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.8" data-path="7.变量的基本使用.html">
            
                <a href="7.变量的基本使用.html">
            
                    
                    7.变量的基本使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.9" data-path="8.变量的命名.html">
            
                <a href="8.变量的命名.html">
            
                    
                    8.变量的命名
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.10" data-path="9.判断（if）语句.html">
            
                <a href="9.判断（if）语句.html">
            
                    
                    9.判断（if）语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.11" data-path="10.运算符.html">
            
                <a href="10.运算符.html">
            
                    
                    10.运算符.md
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="7.12" data-path="11.循环.html">
            
                <a href="11.循环.html">
            
                    
                    11.循环.md
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.13" data-path="12.函数基础.html">
            
                <a href="12.函数基础.html">
            
                    
                    12.函数基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.14" data-path="13.高级变量类型.html">
            
                <a href="13.高级变量类型.html">
            
                    
                    13.函数基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.15" data-path="14.综合应用 —— 名片管理系统.html">
            
                <a href="14.综合应用 —— 名片管理系统.html">
            
                    
                    14.综合应用 —— 名片管理系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.16" data-path="15.变量进阶（理解）.html">
            
                <a href="15.变量进阶（理解）.html">
            
                    
                    15.变量进阶（理解）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.17" data-path="16.函数进阶.html">
            
                <a href="16.函数进阶.html">
            
                    
                    16.函数进阶
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">面对对象</li>
        
        
    
        <li class="chapter " data-level="8.1" data-path="../课余/编程exe.html">
            
                <a href="../课余/编程exe.html">
            
                    
                    编程exe
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">问题</li>
        
        
    
        <li class="chapter " data-level="9.1" data-path="../问题/安装软件.html">
            
                <a href="../问题/安装软件.html">
            
                    
                    安装软件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="9.2" data-path="../问题/激活码网站.html">
            
                <a href="../问题/激活码网站.html">
            
                    
                    激活码网站
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="9.3" data-path="../问题/虚拟机.html">
            
                <a href="../问题/虚拟机.html">
            
                    
                    虚拟机
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="9.4" data-path="../问题/疑难杂症.html">
            
                <a href="../问题/疑难杂症.html">
            
                    
                    疑难杂症
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >11.循环.md</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x5FAA;&#x73AF;">&#x5FAA;&#x73AF;</h1>
<h2 id="&#x76EE;&#x6807;">&#x76EE;&#x6807;</h2>
<ul>
<li>&#x7A0B;&#x5E8F;&#x7684;&#x4E09;&#x5927;&#x6D41;&#x7A0B;</li>
<li>while &#x5FAA;&#x73AF;&#x57FA;&#x672C;&#x4F7F;&#x7528;</li>
<li>break &#x548C; continue</li>
<li>while &#x5FAA;&#x73AF;&#x5D4C;&#x5957;</li>
</ul>
<h2 id="01-&#x7A0B;&#x5E8F;&#x7684;&#x4E09;&#x5927;&#x6D41;&#x7A0B;">01. &#x7A0B;&#x5E8F;&#x7684;&#x4E09;&#x5927;&#x6D41;&#x7A0B;</h2>
<ul>
<li><p>&#x5728;&#x7A0B;&#x5E8F;&#x5F00;&#x53D1;&#x4E2D;&#xFF0C;&#x4E00;&#x5171;&#x6709;&#x4E09;&#x79CD;&#x6D41;&#x7A0B;&#x65B9;&#x5F0F;&#xFF1A;</p>
<ul>
<li><strong>&#x987A;&#x5E8F;</strong> &#x2014;&#x2014; <strong>&#x4ECE;&#x4E0A;&#x5411;&#x4E0B;</strong>&#xFF0C;&#x987A;&#x5E8F;&#x6267;&#x884C;&#x4EE3;&#x7801;</li>
<li><strong>&#x5206;&#x652F;</strong> &#x2014;&#x2014; &#x6839;&#x636E;&#x6761;&#x4EF6;&#x5224;&#x65AD;&#xFF0C;&#x51B3;&#x5B9A;&#x6267;&#x884C;&#x4EE3;&#x7801;&#x7684; <strong>&#x5206;&#x652F;</strong></li>
<li><p><strong>&#x5FAA;&#x73AF;</strong> &#x2014;&#x2014; &#x8BA9; <strong>&#x7279;&#x5B9A;&#x4EE3;&#x7801; &#x91CD;&#x590D;</strong> &#x6267;&#x884C;</p>
<p><img src="https://gitee.com/lichaikui/picture/raw/master/tupian/001_%E7%A8%8B%E5%BA%8F%E4%B8%89%E5%A4%A7%E6%B5%81%E7%A8%8B.png" alt="001_&#x7A0B;&#x5E8F;&#x4E09;&#x5927;&#x6D41;&#x7A0B;"></p>
</li>
</ul>
</li>
</ul>
<h2 id="02-while-&#x5FAA;&#x73AF;&#x57FA;&#x672C;&#x4F7F;&#x7528;">02. <code>while</code> &#x5FAA;&#x73AF;&#x57FA;&#x672C;&#x4F7F;&#x7528;</h2>
<ul>
<li>&#x5FAA;&#x73AF;&#x7684;&#x4F5C;&#x7528;&#x5C31;&#x662F;&#x8BA9; <strong>&#x6307;&#x5B9A;&#x7684;&#x4EE3;&#x7801;</strong> &#x91CD;&#x590D;&#x7684;&#x6267;&#x884C;</li>
<li><p><code>while</code> &#x5FAA;&#x73AF;&#x6700;&#x5E38;&#x7528;&#x7684;&#x5E94;&#x7528;&#x573A;&#x666F;&#x5C31;&#x662F; <strong>&#x8BA9;&#x6267;&#x884C;&#x7684;&#x4EE3;&#x7801;</strong> &#x6309;&#x7167; <strong>&#x6307;&#x5B9A;&#x7684;&#x6B21;&#x6570;</strong> <strong>&#x91CD;&#x590D;</strong> &#x6267;&#x884C;</p>
</li>
<li><p>&#x9700;&#x6C42; &#x2014;&#x2014; &#x6253;&#x5370; 5 &#x904D; <code>Hello Python</code></p>
</li>
<li>&#x601D;&#x8003; &#x2014;&#x2014; &#x5982;&#x679C;&#x8981;&#x6C42;&#x6253;&#x5370; 100 &#x904D;&#x600E;&#x4E48;&#x529E;&#xFF1F;</li>
</ul>
<h3 id="21-while-&#x8BED;&#x53E5;&#x57FA;&#x672C;&#x8BED;&#x6CD5;">2.1 <code>while</code> &#x8BED;&#x53E5;&#x57FA;&#x672C;&#x8BED;&#x6CD5;</h3>
<pre><code class="lang-python">&#x521D;&#x59CB;&#x6761;&#x4EF6;&#x8BBE;&#x7F6E; &#x2014;&#x2014; &#x901A;&#x5E38;&#x662F;&#x91CD;&#x590D;&#x6267;&#x884C;&#x7684; &#x8BA1;&#x6570;&#x5668;

<span class="hljs-keyword">while</span> &#x6761;&#x4EF6;(&#x5224;&#x65AD; &#x8BA1;&#x6570;&#x5668; &#x662F;&#x5426;&#x8FBE;&#x5230; &#x76EE;&#x6807;&#x6B21;&#x6570;):
    &#x6761;&#x4EF6;&#x6EE1;&#x8DB3;&#x65F6;&#xFF0C;&#x505A;&#x7684;&#x4E8B;&#x60C5;<span class="hljs-number">1</span>
    &#x6761;&#x4EF6;&#x6EE1;&#x8DB3;&#x65F6;&#xFF0C;&#x505A;&#x7684;&#x4E8B;&#x60C5;<span class="hljs-number">2</span>
    &#x6761;&#x4EF6;&#x6EE1;&#x8DB3;&#x65F6;&#xFF0C;&#x505A;&#x7684;&#x4E8B;&#x60C5;<span class="hljs-number">3</span>
    ...(&#x7701;&#x7565;)...

    &#x5904;&#x7406;&#x6761;&#x4EF6;(&#x8BA1;&#x6570;&#x5668; + <span class="hljs-number">1</span>)
</code></pre>
<p><strong>&#x6CE8;&#x610F;</strong>&#xFF1A;</p>
<ul>
<li><code>while</code> &#x8BED;&#x53E5;&#x4EE5;&#x53CA;&#x7F29;&#x8FDB;&#x90E8;&#x5206;&#x662F;&#x4E00;&#x4E2A; <strong>&#x5B8C;&#x6574;&#x7684;&#x4EE3;&#x7801;&#x5757;</strong></li>
</ul>
<h4 id="&#x7B2C;&#x4E00;&#x4E2A;-while-&#x5FAA;&#x73AF;">&#x7B2C;&#x4E00;&#x4E2A; while &#x5FAA;&#x73AF;</h4>
<p><strong>&#x9700;&#x6C42;</strong></p>
<ul>
<li>&#x6253;&#x5370; 5 &#x904D; Hello Python</li>
</ul>
<pre><code class="lang-while"># 1. &#x5B9A;&#x4E49;&#x91CD;&#x590D;&#x6B21;&#x6570;&#x8BA1;&#x6570;&#x5668;
i = 1

# 2. &#x4F7F;&#x7528; while &#x5224;&#x65AD;&#x6761;&#x4EF6;
while i &lt;= 5:
    # &#x8981;&#x91CD;&#x590D;&#x6267;&#x884C;&#x7684;&#x4EE3;&#x7801;
    print(&quot;Hello Python&quot;)

    # &#x5904;&#x7406;&#x8BA1;&#x6570;&#x5668; i
    i = i + 1

print(&quot;&#x5FAA;&#x73AF;&#x7ED3;&#x675F;&#x540E;&#x7684; i = %d&quot; % i)
</code></pre>
<blockquote>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x5FAA;&#x73AF;&#x7ED3;&#x675F;&#x540E;&#xFF0C;&#x4E4B;&#x524D;&#x5B9A;&#x4E49;&#x7684;&#x8BA1;&#x6570;&#x5668;&#x6761;&#x4EF6;&#x7684;&#x6570;&#x503C;&#x662F;&#x4F9D;&#x65E7;&#x5B58;&#x5728;&#x7684;</p>
</blockquote>
<h4 id="&#x6B7B;&#x5FAA;&#x73AF;">&#x6B7B;&#x5FAA;&#x73AF;</h4>
<blockquote>
<p>&#x7531;&#x4E8E;&#x7A0B;&#x5E8F;&#x5458;&#x7684;&#x539F;&#x56E0;&#xFF0C;<strong>&#x5FD8;&#x8BB0;</strong> &#x5728;&#x5FAA;&#x73AF;&#x5185;&#x90E8; <strong>&#x4FEE;&#x6539;&#x5FAA;&#x73AF;&#x7684;&#x5224;&#x65AD;&#x6761;&#x4EF6;</strong>&#xFF0C;&#x5BFC;&#x81F4;&#x5FAA;&#x73AF;&#x6301;&#x7EED;&#x6267;&#x884C;&#xFF0C;&#x7A0B;&#x5E8F;&#x65E0;&#x6CD5;&#x7EC8;&#x6B62;&#xFF01;</p>
</blockquote>
<h3 id="22-&#x8D4B;&#x503C;&#x8FD0;&#x7B97;&#x7B26;">2.2 &#x8D4B;&#x503C;&#x8FD0;&#x7B97;&#x7B26;</h3>
<ul>
<li>&#x5728; Python &#x4E2D;&#xFF0C;&#x4F7F;&#x7528; <code>=</code> &#x53EF;&#x4EE5;&#x7ED9;&#x53D8;&#x91CF;&#x8D4B;&#x503C;</li>
<li>&#x5728;&#x7B97;&#x672F;&#x8FD0;&#x7B97;&#x65F6;&#xFF0C;&#x4E3A;&#x4E86;&#x7B80;&#x5316;&#x4EE3;&#x7801;&#x7684;&#x7F16;&#x5199;&#xFF0C;<code>Python</code> &#x8FD8;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x7CFB;&#x5217;&#x7684; &#x4E0E; <strong>&#x7B97;&#x672F;&#x8FD0;&#x7B97;&#x7B26;</strong> &#x5BF9;&#x5E94;&#x7684; <strong>&#x8D4B;&#x503C;&#x8FD0;&#x7B97;&#x7B26;</strong></li>
<li>&#x6CE8;&#x610F;&#xFF1A;<strong>&#x8D4B;&#x503C;&#x8FD0;&#x7B97;&#x7B26;&#x4E2D;&#x95F4;&#x4E0D;&#x80FD;&#x4F7F;&#x7528;&#x7A7A;&#x683C;</strong></li>
</ul>
<table>
<thead>
<tr>
<th>&#x8FD0;&#x7B97;&#x7B26;</th>
<th>&#x63CF;&#x8FF0;</th>
<th>&#x5B9E;&#x4F8B;</th>
</tr>
</thead>
<tbody>
<tr>
<td>=</td>
<td>&#x7B80;&#x5355;&#x7684;&#x8D4B;&#x503C;&#x8FD0;&#x7B97;&#x7B26;</td>
<td>c = a + b &#x5C06; a + b &#x7684;&#x8FD0;&#x7B97;&#x7ED3;&#x679C;&#x8D4B;&#x503C;&#x4E3A; c</td>
</tr>
<tr>
<td>+=</td>
<td>&#x52A0;&#x6CD5;&#x8D4B;&#x503C;&#x8FD0;&#x7B97;&#x7B26;</td>
<td>c += a &#x7B49;&#x6548;&#x4E8E; c = c + a</td>
</tr>
<tr>
<td>-=</td>
<td>&#x51CF;&#x6CD5;&#x8D4B;&#x503C;&#x8FD0;&#x7B97;&#x7B26;</td>
<td>c -= a &#x7B49;&#x6548;&#x4E8E; c = c - a</td>
</tr>
<tr>
<td>*=</td>
<td>&#x4E58;&#x6CD5;&#x8D4B;&#x503C;&#x8FD0;&#x7B97;&#x7B26;</td>
<td>c <em>= a &#x7B49;&#x6548;&#x4E8E; c = c </em> a</td>
</tr>
<tr>
<td>/=</td>
<td>&#x9664;&#x6CD5;&#x8D4B;&#x503C;&#x8FD0;&#x7B97;&#x7B26;</td>
<td>c /= a &#x7B49;&#x6548;&#x4E8E; c = c / a</td>
</tr>
<tr>
<td>//=</td>
<td>&#x53D6;&#x6574;&#x9664;&#x8D4B;&#x503C;&#x8FD0;&#x7B97;&#x7B26;</td>
<td>c //= a &#x7B49;&#x6548;&#x4E8E; c = c // a</td>
</tr>
<tr>
<td>%=</td>
<td>&#x53D6; <strong>&#x6A21;</strong> (&#x4F59;&#x6570;)&#x8D4B;&#x503C;&#x8FD0;&#x7B97;&#x7B26;</td>
<td>c %= a &#x7B49;&#x6548;&#x4E8E; c = c % a</td>
</tr>
<tr>
<td>**=</td>
<td>&#x5E42;&#x8D4B;&#x503C;&#x8FD0;&#x7B97;&#x7B26;</td>
<td>c <strong>= a &#x7B49;&#x6548;&#x4E8E; c = c </strong> a</td>
</tr>
</tbody>
</table>
<h3 id="23-python-&#x4E2D;&#x7684;&#x8BA1;&#x6570;&#x65B9;&#x6CD5;">2.3 Python &#x4E2D;&#x7684;&#x8BA1;&#x6570;&#x65B9;&#x6CD5;</h3>
<p>&#x5E38;&#x89C1;&#x7684;&#x8BA1;&#x6570;&#x65B9;&#x6CD5;&#x6709;&#x4E24;&#x79CD;&#xFF0C;&#x53EF;&#x4EE5;&#x5206;&#x522B;&#x79F0;&#x4E3A;&#xFF1A;</p>
<ul>
<li><strong>&#x81EA;&#x7136;&#x8BA1;&#x6570;&#x6CD5;</strong>&#xFF08;&#x4ECE; <code>1</code> &#x5F00;&#x59CB;&#xFF09;&#x2014;&#x2014; &#x66F4;&#x7B26;&#x5408;&#x4EBA;&#x7C7B;&#x7684;&#x4E60;&#x60EF;</li>
<li><strong>&#x7A0B;&#x5E8F;&#x8BA1;&#x6570;&#x6CD5;</strong>&#xFF08;&#x4ECE; <code>0</code> &#x5F00;&#x59CB;&#xFF09;&#x2014;&#x2014; &#x51E0;&#x4E4E;&#x6240;&#x6709;&#x7684;&#x7A0B;&#x5E8F;&#x8BED;&#x8A00;&#x90FD;&#x9009;&#x62E9;&#x4ECE; 0 &#x5F00;&#x59CB;&#x8BA1;&#x6570;</li>
</ul>
<p>&#x56E0;&#x6B64;&#xFF0C;&#x5927;&#x5BB6;&#x5728;&#x7F16;&#x5199;&#x7A0B;&#x5E8F;&#x65F6;&#xFF0C;&#x5E94;&#x8BE5;&#x5C3D;&#x91CF;&#x517B;&#x6210;&#x4E60;&#x60EF;&#xFF1A;<strong>&#x9664;&#x975E;&#x9700;&#x6C42;&#x7684;&#x7279;&#x6B8A;&#x8981;&#x6C42;&#xFF0C;&#x5426;&#x5219; &#x5FAA;&#x73AF; &#x7684;&#x8BA1;&#x6570;&#x90FD;&#x4ECE; 0 &#x5F00;&#x59CB;</strong></p>
<h3 id="24-&#x5FAA;&#x73AF;&#x8BA1;&#x7B97;">2.4 &#x5FAA;&#x73AF;&#x8BA1;&#x7B97;</h3>
<blockquote>
<p>&#x5728;&#x7A0B;&#x5E8F;&#x5F00;&#x53D1;&#x4E2D;&#xFF0C;&#x901A;&#x5E38;&#x4F1A;&#x9047;&#x5230; <strong>&#x5229;&#x7528;&#x5FAA;&#x73AF;</strong> <strong>&#x91CD;&#x590D;&#x8BA1;&#x7B97;</strong> &#x7684;&#x9700;&#x6C42;</p>
</blockquote>
<p>&#x9047;&#x5230;&#x8FD9;&#x79CD;&#x9700;&#x6C42;&#xFF0C;&#x53EF;&#x4EE5;&#xFF1A;</p>
<ol>
<li>&#x5728; <code>while</code> &#x4E0A;&#x65B9;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#xFF0C;&#x7528;&#x4E8E; <strong>&#x5B58;&#x653E;&#x6700;&#x7EC8;&#x8BA1;&#x7B97;&#x7ED3;&#x679C;</strong></li>
<li>&#x5728;&#x5FAA;&#x73AF;&#x4F53;&#x5185;&#x90E8;&#xFF0C;&#x6BCF;&#x6B21;&#x5FAA;&#x73AF;&#x90FD;&#x7528; <strong>&#x6700;&#x65B0;&#x7684;&#x8BA1;&#x7B97;&#x7ED3;&#x679C;</strong>&#xFF0C;<strong>&#x66F4;&#x65B0;</strong> &#x4E4B;&#x524D;&#x5B9A;&#x4E49;&#x7684;&#x53D8;&#x91CF;</li>
</ol>
<p><strong>&#x9700;&#x6C42;</strong></p>
<ul>
<li>&#x8BA1;&#x7B97; 0 ~ 100 &#x4E4B;&#x95F4;&#x6240;&#x6709;&#x6570;&#x5B57;&#x7684;&#x7D2F;&#x8BA1;&#x6C42;&#x548C;&#x7ED3;&#x679C;</li>
</ul>
<pre><code class="lang-python"><span class="hljs-comment"># &#x8BA1;&#x7B97; 0 ~ 100 &#x4E4B;&#x95F4;&#x6240;&#x6709;&#x6570;&#x5B57;&#x7684;&#x7D2F;&#x8BA1;&#x6C42;&#x548C;&#x7ED3;&#x679C;</span>
<span class="hljs-comment"># 0. &#x5B9A;&#x4E49;&#x6700;&#x7EC8;&#x7ED3;&#x679C;&#x7684;&#x53D8;&#x91CF;</span>
result = <span class="hljs-number">0</span>

<span class="hljs-comment"># 1. &#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x6574;&#x6570;&#x7684;&#x53D8;&#x91CF;&#x8BB0;&#x5F55;&#x5FAA;&#x73AF;&#x7684;&#x6B21;&#x6570;</span>
i = <span class="hljs-number">0</span>

<span class="hljs-comment"># 2. &#x5F00;&#x59CB;&#x5FAA;&#x73AF;</span>
<span class="hljs-keyword">while</span> i &lt;= <span class="hljs-number">100</span>:
    print(i)

    <span class="hljs-comment"># &#x6BCF;&#x4E00;&#x6B21;&#x5FAA;&#x73AF;&#xFF0C;&#x90FD;&#x8BA9; result &#x8FD9;&#x4E2A;&#x53D8;&#x91CF;&#x548C; i &#x8FD9;&#x4E2A;&#x8BA1;&#x6570;&#x5668;&#x76F8;&#x52A0;</span>
    result += i

    <span class="hljs-comment"># &#x5904;&#x7406;&#x8BA1;&#x6570;&#x5668;</span>
    i += <span class="hljs-number">1</span>

print(<span class="hljs-string">&quot;0~100&#x4E4B;&#x95F4;&#x7684;&#x6570;&#x5B57;&#x6C42;&#x548C;&#x7ED3;&#x679C; = %d&quot;</span> % result)
</code></pre>
<h4 id="&#x9700;&#x6C42;&#x8FDB;&#x9636;">&#x9700;&#x6C42;&#x8FDB;&#x9636;</h4>
<ul>
<li>&#x8BA1;&#x7B97; 0 ~ 100 &#x4E4B;&#x95F4; &#x6240;&#x6709; <strong>&#x5076;&#x6570;</strong> &#x7684;&#x7D2F;&#x8BA1;&#x6C42;&#x548C;&#x7ED3;&#x679C;</li>
</ul>
<p>&#x5F00;&#x53D1;&#x6B65;&#x9AA4;</p>
<ol>
<li>&#x7F16;&#x5199;&#x5FAA;&#x73AF; <strong>&#x786E;&#x8BA4;</strong> <strong>&#x8981;&#x8BA1;&#x7B97;&#x7684;&#x6570;&#x5B57;</strong></li>
<li>&#x6DFB;&#x52A0; <strong>&#x7ED3;&#x679C;</strong> &#x53D8;&#x91CF;&#xFF0C;&#x5728;&#x5FAA;&#x73AF;&#x5185;&#x90E8; <strong>&#x5904;&#x7406;&#x8BA1;&#x7B97;&#x7ED3;&#x679C;</strong></li>
</ol>
<pre><code class="lang-python"><span class="hljs-comment"># 0. &#x6700;&#x7EC8;&#x7ED3;&#x679C;</span>
result = <span class="hljs-number">0</span>

<span class="hljs-comment"># 1. &#x8BA1;&#x6570;&#x5668;</span>
i = <span class="hljs-number">0</span>

<span class="hljs-comment"># 2. &#x5F00;&#x59CB;&#x5FAA;&#x73AF;</span>
<span class="hljs-keyword">while</span> i &lt;= <span class="hljs-number">100</span>:

    <span class="hljs-comment"># &#x5224;&#x65AD;&#x5076;&#x6570;</span>
    <span class="hljs-keyword">if</span> i % <span class="hljs-number">2</span> == <span class="hljs-number">0</span>:
        print(i)
        result += i

    <span class="hljs-comment"># &#x5904;&#x7406;&#x8BA1;&#x6570;&#x5668;</span>
    i += <span class="hljs-number">1</span>

print(<span class="hljs-string">&quot;0~100&#x4E4B;&#x95F4;&#x5076;&#x6570;&#x6C42;&#x548C;&#x7ED3;&#x679C; = %d&quot;</span> % result)
</code></pre>
<h2 id="03-break-&#x548C;-continue">03. break &#x548C; continue</h2>
<blockquote>
<p><code>break</code> &#x548C; <code>continue</code> &#x662F;&#x4E13;&#x95E8;&#x5728;&#x5FAA;&#x73AF;&#x4E2D;&#x4F7F;&#x7528;&#x7684;&#x5173;&#x952E;&#x5B57;</p>
</blockquote>
<ul>
<li><code>break</code> <strong>&#x67D0;&#x4E00;&#x6761;&#x4EF6;&#x6EE1;&#x8DB3;&#x65F6;</strong>&#xFF0C;&#x9000;&#x51FA;&#x5FAA;&#x73AF;&#xFF0C;&#x4E0D;&#x518D;&#x6267;&#x884C;&#x540E;&#x7EED;&#x91CD;&#x590D;&#x7684;&#x4EE3;&#x7801;</li>
<li><code>continue</code> <strong>&#x67D0;&#x4E00;&#x6761;&#x4EF6;&#x6EE1;&#x8DB3;&#x65F6;</strong>&#xFF0C;&#x4E0D;&#x6267;&#x884C;&#x540E;&#x7EED;&#x91CD;&#x590D;&#x7684;&#x4EE3;&#x7801;</li>
</ul>
<blockquote>
<p><code>break</code> &#x548C; <code>continue</code> &#x53EA;&#x9488;&#x5BF9; <strong>&#x5F53;&#x524D;&#x6240;&#x5728;&#x5FAA;&#x73AF;</strong> &#x6709;&#x6548;</p>
</blockquote>
<p><img src="https://gitee.com/lichaikui/picture/raw/master/tupian/002_%E5%BE%AA%E7%8E%AF%E6%B5%81%E7%A8%8B%E5%9B%BE.png" alt="002_&#x5FAA;&#x73AF;&#x6D41;&#x7A0B;&#x56FE;-w400"></p>
<h3 id="31-break">3.1 break</h3>
<ul>
<li><strong>&#x5728;&#x5FAA;&#x73AF;&#x8FC7;&#x7A0B;&#x4E2D;</strong>&#xFF0C;&#x5982;&#x679C; <strong>&#x67D0;&#x4E00;&#x4E2A;&#x6761;&#x4EF6;&#x6EE1;&#x8DB3;&#x540E;</strong>&#xFF0C;<strong>&#x4E0D;</strong> &#x518D;&#x5E0C;&#x671B; <strong>&#x5FAA;&#x73AF;&#x7EE7;&#x7EED;&#x6267;&#x884C;</strong>&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; <code>break</code> &#x9000;&#x51FA;&#x5FAA;&#x73AF;</li>
</ul>
<pre><code class="lang-python">i = <span class="hljs-number">0</span>

<span class="hljs-keyword">while</span> i &lt; <span class="hljs-number">10</span>:

    <span class="hljs-comment"># break &#x67D0;&#x4E00;&#x6761;&#x4EF6;&#x6EE1;&#x8DB3;&#x65F6;&#xFF0C;&#x9000;&#x51FA;&#x5FAA;&#x73AF;&#xFF0C;&#x4E0D;&#x518D;&#x6267;&#x884C;&#x540E;&#x7EED;&#x91CD;&#x590D;&#x7684;&#x4EE3;&#x7801;</span>
    <span class="hljs-comment"># i == 3</span>
    <span class="hljs-keyword">if</span> i == <span class="hljs-number">3</span>:
        <span class="hljs-keyword">break</span>

    print(i)

    i += <span class="hljs-number">1</span>

print(<span class="hljs-string">&quot;over&quot;</span>)
</code></pre>
<blockquote>
<p><code>break</code> &#x53EA;&#x9488;&#x5BF9;&#x5F53;&#x524D;&#x6240;&#x5728;&#x5FAA;&#x73AF;&#x6709;&#x6548;</p>
</blockquote>
<h3 id="32-continue">3.2 continue</h3>
<ul>
<li><strong>&#x5728;&#x5FAA;&#x73AF;&#x8FC7;&#x7A0B;&#x4E2D;</strong>&#xFF0C;&#x5982;&#x679C; <strong>&#x67D0;&#x4E00;&#x4E2A;&#x6761;&#x4EF6;&#x6EE1;&#x8DB3;&#x540E;</strong>&#xFF0C;<strong>&#x4E0D;</strong> &#x5E0C;&#x671B; <strong>&#x6267;&#x884C;&#x5FAA;&#x73AF;&#x4EE3;&#x7801;&#xFF0C;&#x4F46;&#x662F;&#x53C8;&#x4E0D;&#x5E0C;&#x671B;&#x9000;&#x51FA;&#x5FAA;&#x73AF;</strong>&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; <code>continue</code></li>
<li>&#x4E5F;&#x5C31;&#x662F;&#xFF1A;&#x5728;&#x6574;&#x4E2A;&#x5FAA;&#x73AF;&#x4E2D;&#xFF0C;<strong>&#x53EA;&#x6709;&#x67D0;&#x4E9B;&#x6761;&#x4EF6;</strong>&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x6267;&#x884C;&#x5FAA;&#x73AF;&#x4EE3;&#x7801;&#xFF0C;&#x800C;&#x5176;&#x4ED6;&#x6761;&#x4EF6;&#x90FD;&#x9700;&#x8981;&#x6267;&#x884C;</li>
</ul>
<pre><code class="lang-python">i = <span class="hljs-number">0</span>

<span class="hljs-keyword">while</span> i &lt; <span class="hljs-number">10</span>:

    <span class="hljs-comment"># &#x5F53; i == 7 &#x65F6;&#xFF0C;&#x4E0D;&#x5E0C;&#x671B;&#x6267;&#x884C;&#x9700;&#x8981;&#x91CD;&#x590D;&#x6267;&#x884C;&#x7684;&#x4EE3;&#x7801;</span>
    <span class="hljs-keyword">if</span> i == <span class="hljs-number">7</span>:
        <span class="hljs-comment"># &#x5728;&#x4F7F;&#x7528; continue &#x4E4B;&#x524D;&#xFF0C;&#x540C;&#x6837;&#x5E94;&#x8BE5;&#x4FEE;&#x6539;&#x8BA1;&#x6570;&#x5668;</span>
        <span class="hljs-comment"># &#x5426;&#x5219;&#x4F1A;&#x51FA;&#x73B0;&#x6B7B;&#x5FAA;&#x73AF;</span>
        i += <span class="hljs-number">1</span>   &#xFF08; &#x66F4;&#x6539;&#x6B64;&#x5904; i += <span class="hljs-number">2</span> &#x5219;&#x53EF;&#x8DF3;&#x8FC7;&#x8F93;&#x51FA; <span class="hljs-number">8</span>   ==&#x300B;&#x8DF3;&#x8FC7;&#x4E00;&#x6BB5;&#x5FAA;&#x73AF; &#xFF09;

        <span class="hljs-keyword">continue</span>

    <span class="hljs-comment"># &#x91CD;&#x590D;&#x6267;&#x884C;&#x7684;&#x4EE3;&#x7801;</span>
    print(i)

    i += <span class="hljs-number">1</span>
</code></pre>
<ul>
<li>&#x9700;&#x8981;&#x6CE8;&#x610F;&#xFF1A;&#x4F7F;&#x7528; <code>continue</code> &#x65F6;&#xFF0C;<strong>&#x6761;&#x4EF6;&#x5904;&#x7406;&#x90E8;&#x5206;&#x7684;&#x4EE3;&#x7801;&#xFF0C;&#x9700;&#x8981;&#x7279;&#x522B;&#x6CE8;&#x610F;</strong>&#xFF0C;&#x4E0D;&#x5C0F;&#x5FC3;&#x4F1A;&#x51FA;&#x73B0; <strong>&#x6B7B;&#x5FAA;&#x73AF;</strong></li>
</ul>
<blockquote>
<p><code>continue</code> &#x53EA;&#x9488;&#x5BF9;&#x5F53;&#x524D;&#x6240;&#x5728;&#x5FAA;&#x73AF;&#x6709;&#x6548;</p>
</blockquote>
<pre><code>&#x975E;break = continue
</code></pre><h2 id="04-while-&#x5FAA;&#x73AF;&#x5D4C;&#x5957;">04. <code>while</code> &#x5FAA;&#x73AF;&#x5D4C;&#x5957;</h2>
<h3 id="41-&#x5FAA;&#x73AF;&#x5D4C;&#x5957;">4.1 &#x5FAA;&#x73AF;&#x5D4C;&#x5957;</h3>
<ul>
<li><code>while</code> &#x5D4C;&#x5957;&#x5C31;&#x662F;&#xFF1A;<code>while</code> &#x91CC;&#x9762;&#x8FD8;&#x6709; <code>while</code></li>
</ul>
<pre><code class="lang-python"><span class="hljs-keyword">while</span> &#x6761;&#x4EF6; <span class="hljs-number">1</span>:
    &#x6761;&#x4EF6;&#x6EE1;&#x8DB3;&#x65F6;&#xFF0C;&#x505A;&#x7684;&#x4E8B;&#x60C5;<span class="hljs-number">1</span>
    &#x6761;&#x4EF6;&#x6EE1;&#x8DB3;&#x65F6;&#xFF0C;&#x505A;&#x7684;&#x4E8B;&#x60C5;<span class="hljs-number">2</span>
    &#x6761;&#x4EF6;&#x6EE1;&#x8DB3;&#x65F6;&#xFF0C;&#x505A;&#x7684;&#x4E8B;&#x60C5;<span class="hljs-number">3</span>
    ...(&#x7701;&#x7565;)...

    <span class="hljs-keyword">while</span> &#x6761;&#x4EF6; <span class="hljs-number">2</span>:
        &#x6761;&#x4EF6;&#x6EE1;&#x8DB3;&#x65F6;&#xFF0C;&#x505A;&#x7684;&#x4E8B;&#x60C5;<span class="hljs-number">1</span>
        &#x6761;&#x4EF6;&#x6EE1;&#x8DB3;&#x65F6;&#xFF0C;&#x505A;&#x7684;&#x4E8B;&#x60C5;<span class="hljs-number">2</span>
        &#x6761;&#x4EF6;&#x6EE1;&#x8DB3;&#x65F6;&#xFF0C;&#x505A;&#x7684;&#x4E8B;&#x60C5;<span class="hljs-number">3</span>
        ...(&#x7701;&#x7565;)...

        &#x5904;&#x7406;&#x6761;&#x4EF6; <span class="hljs-number">2</span>

    &#x5904;&#x7406;&#x6761;&#x4EF6; <span class="hljs-number">1</span>
</code></pre>
<h3 id="42-&#x5FAA;&#x73AF;&#x5D4C;&#x5957;&#x6F14;&#x7EC3;-&#x2014;&#x2014;-&#x4E5D;&#x4E5D;&#x4E58;&#x6CD5;&#x8868;">4.2 &#x5FAA;&#x73AF;&#x5D4C;&#x5957;&#x6F14;&#x7EC3; &#x2014;&#x2014; &#x4E5D;&#x4E5D;&#x4E58;&#x6CD5;&#x8868;</h3>
<h4 id="&#x7B2C;-1-&#x6B65;&#xFF1A;&#x7528;&#x5D4C;&#x5957;&#x6253;&#x5370;&#x5C0F;&#x661F;&#x661F;">&#x7B2C; 1 &#x6B65;&#xFF1A;&#x7528;&#x5D4C;&#x5957;&#x6253;&#x5370;&#x5C0F;&#x661F;&#x661F;</h4>
<p><strong>&#x9700;&#x6C42;</strong></p>
<ul>
<li>&#x5728;&#x63A7;&#x5236;&#x53F0;&#x8FDE;&#x7EED;&#x8F93;&#x51FA;&#x4E94;&#x884C; <code>*</code>&#xFF0C;&#x6BCF;&#x4E00;&#x884C;&#x661F;&#x53F7;&#x7684;&#x6570;&#x91CF;&#x4F9D;&#x6B21;&#x9012;&#x589E;</li>
</ul>
<pre><code>*
**
***
****
*****
</code></pre><ul>
<li>&#x4F7F;&#x7528;&#x5B57;&#x7B26;&#x4E32; * &#x6253;&#x5370;</li>
</ul>
<pre><code class="lang-python"><span class="hljs-comment"># 1. &#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x8BA1;&#x6570;&#x5668;&#x53D8;&#x91CF;&#xFF0C;&#x4ECE;&#x6570;&#x5B57;1&#x5F00;&#x59CB;&#xFF0C;&#x5FAA;&#x73AF;&#x4F1A;&#x6BD4;&#x8F83;&#x65B9;&#x4FBF;</span>
row = <span class="hljs-number">1</span>

<span class="hljs-keyword">while</span> row &lt;= <span class="hljs-number">5</span>:

    print(<span class="hljs-string">&quot;*&quot;</span> * row)

    row += <span class="hljs-number">1</span>
</code></pre>
<h4 id="&#x7B2C;-2-&#x6B65;&#xFF1A;&#x4F7F;&#x7528;&#x5FAA;&#x73AF;&#x5D4C;&#x5957;&#x6253;&#x5370;&#x5C0F;&#x661F;&#x661F;">&#x7B2C; 2 &#x6B65;&#xFF1A;&#x4F7F;&#x7528;&#x5FAA;&#x73AF;&#x5D4C;&#x5957;&#x6253;&#x5370;&#x5C0F;&#x661F;&#x661F;</h4>
<p><strong>&#x77E5;&#x8BC6;&#x70B9;</strong> &#x5BF9; <code>print</code> &#x51FD;&#x6570;&#x7684;&#x4F7F;&#x7528;&#x505A;&#x4E00;&#x4E2A;&#x589E;&#x5F3A;</p>
<ul>
<li>&#x5728;&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;<code>print</code> &#x51FD;&#x6570;&#x8F93;&#x51FA;&#x5185;&#x5BB9;&#x4E4B;&#x540E;&#xFF0C;&#x4F1A;&#x81EA;&#x52A8;&#x5728;&#x5185;&#x5BB9;&#x672B;&#x5C3E;&#x589E;&#x52A0;&#x6362;&#x884C;</li>
<li>&#x5982;&#x679C;&#x4E0D;&#x5E0C;&#x671B;&#x672B;&#x5C3E;&#x589E;&#x52A0;&#x6362;&#x884C;&#xFF0C;&#x53EF;&#x4EE5;&#x5728; <code>print</code> &#x51FD;&#x6570;&#x8F93;&#x51FA;&#x5185;&#x5BB9;&#x7684;&#x540E;&#x9762;&#x589E;&#x52A0; <code>, end=&quot;&quot;</code></li>
<li><p>&#x5176;&#x4E2D; <code>&quot;&quot;</code> &#x4E2D;&#x95F4;&#x53EF;&#x4EE5;&#x6307;&#x5B9A; <code>print</code> &#x51FD;&#x6570;&#x8F93;&#x51FA;&#x5185;&#x5BB9;&#x4E4B;&#x540E;&#xFF0C;&#x7EE7;&#x7EED;&#x5E0C;&#x671B;&#x663E;&#x793A;&#x7684;&#x5185;&#x5BB9;</p>
</li>
<li><p>&#x8BED;&#x6CD5;&#x683C;&#x5F0F;&#x5982;&#x4E0B;&#xFF1A;</p>
</li>
</ul>
<pre><code class="lang-python"><span class="hljs-comment"># &#x5411;&#x63A7;&#x5236;&#x53F0;&#x8F93;&#x51FA;&#x5185;&#x5BB9;&#x7ED3;&#x675F;&#x4E4B;&#x540E;&#xFF0C;&#x4E0D;&#x4F1A;&#x6362;&#x884C;</span>
print(<span class="hljs-string">&quot;*&quot;</span>, end=<span class="hljs-string">&quot;&quot;</span>)

<span class="hljs-comment"># &#x5355;&#x7EAF;&#x7684;&#x6362;&#x884C;</span>
print(<span class="hljs-string">&quot;&quot;</span>)
</code></pre>
<blockquote>
<p><code>end=&quot;&quot;</code> &#x8868;&#x793A;&#x5411;&#x63A7;&#x5236;&#x53F0;&#x8F93;&#x51FA;&#x5185;&#x5BB9;&#x7ED3;&#x675F;&#x4E4B;&#x540E;&#xFF0C;&#x4E0D;&#x4F1A;&#x6362;&#x884C;</p>
</blockquote>
<p><strong>&#x5047;&#x8BBE;</strong> <code>Python</code> <strong>&#x6CA1;&#x6709;&#x63D0;&#x4F9B;</strong> &#x5B57;&#x7B26;&#x4E32;&#x7684; <code>*</code> &#x64CD;&#x4F5C; <strong>&#x62FC;&#x63A5;&#x5B57;&#x7B26;&#x4E32;</strong></p>
<p><strong>&#x9700;&#x6C42;</strong></p>
<ul>
<li>&#x5728;&#x63A7;&#x5236;&#x53F0;&#x8FDE;&#x7EED;&#x8F93;&#x51FA;&#x4E94;&#x884C; <code>*</code>&#xFF0C;&#x6BCF;&#x4E00;&#x884C;&#x661F;&#x53F7;&#x7684;&#x6570;&#x91CF;&#x4F9D;&#x6B21;&#x9012;&#x589E;</li>
</ul>
<pre><code>*
**
***
****
*****
</code></pre><p><strong>&#x5F00;&#x53D1;&#x6B65;&#x9AA4;</strong></p>
<ul>
<li>1&gt; &#x5B8C;&#x6210; 5 &#x884C;&#x5185;&#x5BB9;&#x7684;&#x7B80;&#x5355;&#x8F93;&#x51FA;</li>
<li>2&gt; &#x5206;&#x6790;&#x6BCF;&#x884C;&#x5185;&#x90E8;&#x7684; <code>*</code> &#x5E94;&#x8BE5;&#x5982;&#x4F55;&#x5904;&#x7406;&#xFF1F;<ul>
<li>&#x6BCF;&#x884C;&#x663E;&#x793A;&#x7684;&#x661F;&#x661F;&#x548C;&#x5F53;&#x524D;&#x6240;&#x5728;&#x7684;&#x884C;&#x6570;&#x662F;&#x4E00;&#x81F4;&#x7684;</li>
<li>&#x5D4C;&#x5957;&#x4E00;&#x4E2A;&#x5C0F;&#x7684;&#x5FAA;&#x73AF;&#xFF0C;&#x4E13;&#x95E8;&#x5904;&#x7406;&#x6BCF;&#x4E00;&#x884C;&#x4E2D; <code>&#x5217;</code> &#x7684;&#x661F;&#x661F;&#x663E;&#x793A;  </li>
</ul>
</li>
</ul>
<pre><code class="lang-python">row = <span class="hljs-number">1</span>

<span class="hljs-keyword">while</span> row &lt;= <span class="hljs-number">5</span>:

    <span class="hljs-comment"># &#x5047;&#x8BBE; python &#x6CA1;&#x6709;&#x63D0;&#x4F9B;&#x5B57;&#x7B26;&#x4E32; * &#x64CD;&#x4F5C;</span>
    <span class="hljs-comment"># &#x5728;&#x5FAA;&#x73AF;&#x5185;&#x90E8;&#xFF0C;&#x518D;&#x589E;&#x52A0;&#x4E00;&#x4E2A;&#x5FAA;&#x73AF;&#xFF0C;&#x5B9E;&#x73B0;&#x6BCF;&#x4E00;&#x884C;&#x7684; &#x661F;&#x661F; &#x6253;&#x5370;</span>
    col = <span class="hljs-number">1</span>

    <span class="hljs-keyword">while</span> col &lt;= row:
        print(<span class="hljs-string">&quot;*&quot;</span>, end=<span class="hljs-string">&quot;&quot;</span>)

        col += <span class="hljs-number">1</span>

    <span class="hljs-comment"># &#x6BCF;&#x4E00;&#x884C;&#x661F;&#x53F7;&#x8F93;&#x51FA;&#x5B8C;&#x6210;&#x540E;&#xFF0C;&#x518D;&#x589E;&#x52A0;&#x4E00;&#x4E2A;&#x6362;&#x884C;</span>
    print(<span class="hljs-string">&quot;&quot;</span>)

    row += <span class="hljs-number">1</span>
</code></pre>
<h4 id="&#x7B2C;-3-&#x6B65;&#xFF1A;-&#x4E5D;&#x4E5D;&#x4E58;&#x6CD5;&#x8868;">&#x7B2C; 3 &#x6B65;&#xFF1A; &#x4E5D;&#x4E5D;&#x4E58;&#x6CD5;&#x8868;</h4>
<p><strong>&#x9700;&#x6C42;</strong> &#x8F93;&#x51FA; &#x4E5D;&#x4E5D;&#x4E58;&#x6CD5;&#x8868;&#xFF0C;&#x683C;&#x5F0F;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code>1 * 1 = 1    
1 * 2 = 2    2 * 2 = 4    
1 * 3 = 3    2 * 3 = 6    3 * 3 = 9    
1 * 4 = 4    2 * 4 = 8    3 * 4 = 12    4 * 4 = 16    
1 * 5 = 5    2 * 5 = 10    3 * 5 = 15    4 * 5 = 20    5 * 5 = 25    
1 * 6 = 6    2 * 6 = 12    3 * 6 = 18    4 * 6 = 24    5 * 6 = 30    6 * 6 = 36    
1 * 7 = 7    2 * 7 = 14    3 * 7 = 21    4 * 7 = 28    5 * 7 = 35    6 * 7 = 42    7 * 7 = 49    
1 * 8 = 8    2 * 8 = 16    3 * 8 = 24    4 * 8 = 32    5 * 8 = 40    6 * 8 = 48    7 * 8 = 56    8 * 8 = 64    
1 * 9 = 9    2 * 9 = 18    3 * 9 = 27    4 * 9 = 36    5 * 9 = 45    6 * 9 = 54    7 * 9 = 63    8 * 9 = 72    9 * 9 = 81
</code></pre><p><strong>&#x5F00;&#x53D1;&#x6B65;&#x9AA4;</strong></p>
<ul>
<li><ol>
<li>&#x6253;&#x5370; 9 &#x884C;&#x5C0F;&#x661F;&#x661F;</li>
</ol>
</li>
</ul>
<pre><code>*
**
***
****
*****
******
*******
********
*********
</code></pre><ul>
<li><ol>
<li>&#x5C06;&#x6BCF;&#x4E00;&#x4E2A; <code>*</code> &#x66FF;&#x6362;&#x6210;&#x5BF9;&#x5E94;&#x7684;&#x884C;&#x4E0E;&#x5217;&#x76F8;&#x4E58;</li>
</ol>
</li>
</ul>
<pre><code class="lang-python"><span class="hljs-comment"># &#x5B9A;&#x4E49;&#x8D77;&#x59CB;&#x884C;</span>
row = <span class="hljs-number">1</span>

<span class="hljs-comment"># &#x6700;&#x5927;&#x6253;&#x5370; 9 &#x884C;</span>
<span class="hljs-keyword">while</span> row &lt;= <span class="hljs-number">9</span>:
    <span class="hljs-comment"># &#x5B9A;&#x4E49;&#x8D77;&#x59CB;&#x5217;</span>
    col = <span class="hljs-number">1</span>

    <span class="hljs-comment"># &#x6700;&#x5927;&#x6253;&#x5370; row &#x5217;</span>
    <span class="hljs-keyword">while</span> col &lt;= row:

        <span class="hljs-comment"># end = &quot;&quot;&#xFF0C;&#x8868;&#x793A;&#x8F93;&#x51FA;&#x7ED3;&#x675F;&#x540E;&#xFF0C;&#x4E0D;&#x6362;&#x884C;</span>
        <span class="hljs-comment"># &quot;\t&quot; &#x53EF;&#x4EE5;&#x5728;&#x63A7;&#x5236;&#x53F0;&#x8F93;&#x51FA;&#x4E00;&#x4E2A;&#x5236;&#x8868;&#x7B26;&#xFF0C;&#x534F;&#x52A9;&#x5728;&#x8F93;&#x51FA;&#x6587;&#x672C;&#x65F6;&#x5BF9;&#x9F50;</span>
        print(<span class="hljs-string">&quot;%d * %d = %d&quot;</span> % (col, row, row * col), end=<span class="hljs-string">&quot;\t&quot;</span>)

        <span class="hljs-comment"># &#x5217;&#x6570; + 1</span>
        col += <span class="hljs-number">1</span>

    <span class="hljs-comment"># &#x4E00;&#x884C;&#x6253;&#x5370;&#x5B8C;&#x6210;&#x7684;&#x6362;&#x884C;</span>
    print(<span class="hljs-string">&quot;&quot;</span>)

    <span class="hljs-comment"># &#x884C;&#x6570; + 1</span>
    row += <span class="hljs-number">1</span>
</code></pre>
<p><strong>&#x5B57;&#x7B26;&#x4E32;&#x4E2D;&#x7684;&#x8F6C;&#x4E49;&#x5B57;&#x7B26;</strong></p>
<ul>
<li><code>\t</code> &#x5728;&#x63A7;&#x5236;&#x53F0;&#x8F93;&#x51FA;&#x4E00;&#x4E2A; <strong>&#x5236;&#x8868;&#x7B26;</strong>&#xFF0C;&#x534F;&#x52A9;&#x5728;&#x8F93;&#x51FA;&#x6587;&#x672C;&#x65F6; <strong>&#x5782;&#x76F4;&#x65B9;&#x5411;</strong> &#x4FDD;&#x6301;&#x5BF9;&#x9F50;</li>
<li><code>\n</code> &#x5728;&#x63A7;&#x5236;&#x53F0;&#x8F93;&#x51FA;&#x4E00;&#x4E2A; <strong>&#x6362;&#x884C;&#x7B26;</strong></li>
</ul>
<blockquote>
<p><strong>&#x5236;&#x8868;&#x7B26;</strong> &#x7684;&#x529F;&#x80FD;&#x662F;&#x5728;&#x4E0D;&#x4F7F;&#x7528;&#x8868;&#x683C;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#x5728; <strong>&#x5782;&#x76F4;&#x65B9;&#x5411;</strong> &#x6309;&#x5217;&#x5BF9;&#x9F50;&#x6587;&#x672C;</p>
</blockquote>
<table>
<thead>
<tr>
<th>&#x8F6C;&#x4E49;&#x5B57;&#x7B26;</th>
<th>&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td>\\</td>
<td>&#x53CD;&#x659C;&#x6760;&#x7B26;&#x53F7;</td>
</tr>
<tr>
<td>\&apos;</td>
<td>&#x5355;&#x5F15;&#x53F7;</td>
</tr>
<tr>
<td>\&quot;</td>
<td>&#x53CC;&#x5F15;&#x53F7;</td>
</tr>
<tr>
<td>\n</td>
<td>&#x6362;&#x884C;</td>
</tr>
<tr>
<td>\t</td>
<td>&#x6A2A;&#x5411;&#x5236;&#x8868;&#x7B26;</td>
</tr>
<tr>
<td>\r</td>
<td>&#x56DE;&#x8F66;</td>
</tr>
</tbody>
</table>
<p>&#x200B;    <img src="https://gitee.com/lichaikui/picture/raw/master/tupian/image-20211231093938346.png" alt="image-20211231093938346"></p>
<p><img src="https://gitee.com/lichaikui/picture/raw/master/tupian/image-20211231094046832.png" alt="image-20211231094046832"></p>
<p><img src="https://gitee.com/lichaikui/picture/raw/master/tupian/image-20211231094945065.png" alt="image-20211231094945065"></p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="10.运算符.html" class="navigation navigation-prev " aria-label="Previous page: 10.运算符.md">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="12.函数基础.html" class="navigation navigation-next " aria-label="Next page: 12.函数基础">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"11.循环.md","level":"7.12","depth":1,"next":{"title":"12.函数基础","level":"7.13","depth":1,"path":"python面对过程学习/12.函数基础.md","ref":"./python面对过程学习/12.函数基础.md","articles":[]},"previous":{"title":"10.运算符.md","level":"7.11","depth":1,"path":"python面对过程学习/10.运算符.md","ref":"./python面对过程学习/10.运算符.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"python面对过程学习/11.循环.md","mtime":"2022-01-10T16:19:03.038Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2022-03-24T13:44:59.630Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

